import echarts from 'echarts';
// 引入柱状图
import 'echarts/lib/chart/bar';
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import storageApi from '../../../core/storage/storage';

function patrolRankController($rootScope, $scope, homeStatsService) {
  'ngInject';

  this.view = {
    isTodaySelected: true,
  };

   // 巡查情况
  this.getCheck = (type) => {
    const reqParam = { type };
    reqParam.orgId = $scope.orgId;
    if (type === 1) {
      this.view.isTodaySelected = true;
    } else {
      this.view.isTodaySelected = false;
    }
    this.hasCheckProcess = false;
    homeStatsService
      .queryCheck({ mapParams: reqParam })
      .then((res) => {
        if (res.success) {
          this.checkList = res.rows;
          if (this.checkList && this.checkList.length > 0) {
            this.hasCheckProcess = true;
            const max = _.max(this.checkList.map(i => i.patrolNums));
            this.checkList.forEach((item) => {
              const percentage = (item.patrolNums / max) * 100;
              item.percentage = `${percentage}%`;
              item.width = { width: item.percentage };
            });
          } else {
            this.hasCheckProcess = false;
          }
        }
      });
  };

  this.getCheck(1);
}

export default patrolRankController;
